import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class AppletVersionService extends BaseService<any> {
  private readonly logger = new Logger(AppletVersionService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * getPage
   * 对应 PHP: AppletVersionService_admin::getPage()
   * 逻辑类型: undefined - undefined
   */
  async getPage(where: any[]) {
    // 基于PHP真实逻辑: getPage
    // PHP原文: return $this->core_applet_version_service->getPage($where);     }      /**      * 获取信息      * @param int $id      * @return array      */     public f...
return this.core_applet_version_service.getPage(where);
    }

    /**
     * 获取信息
     * @param int id
     * @return */
    async getInfo(int id)
    {
        return this.core_applet_version_service.getInfo(id);
    }

    /**
     * 添加
     * @param data
     * @return true
     */
    async add(data)
    {
        data.version_num = version_to_int(data.version];//版本号数字
        data.uid = this.uid;//发布者
        data.status = AppletlDict.OFF;
        this.model.create(data);
        return true;
    }
    /**
     * 上传小程序包
     * @param file
     * @return * @throws BusinessException
     */
    async upload(file){
        const core_upload_service = this.coreUploadService;
        const type = FileDict.APPLET;
        const dir = '/applet/'.type + '/version/';
        return core_upload_service.document(file, this.site_id, type, dir, FileDict.LOCAL);
    }

    /**
     * 设置版本状态
     * @param int id
     * @param status
     * @return true
     */
    async setStatus(int id, status){
        const data = [
            status: status
        ];
        const where = [
            ['id', '=', id)
        ];
        this.model.where(where).update(data);
        return true;
    }

    /**
     * 编辑
     * @param int id
     * @param data
     * @return true
     */
    async edit(int id, data)
    {
        data.version_num = version_to_int(data.version];//版本号数字
        data.status = AppletlDict.OFF;
        data.update_time = time(];
        this.model.where([['id', '=', id))).create(data);
        return true;
    }

    /**
     * 删除
     * @param int id
     * @return true
     */
    async del(int id){
        this.model.where([['id', '=', id))).delete(];
        return true;
    }

}
  }

  /**
   * getInfo
   * 对应 PHP: AppletVersionService_admin::getInfo()
   * 逻辑类型: undefined - undefined
   */
  async getInfo(id: number) {
    // 基于PHP真实逻辑: getInfo
    // PHP原文: return $this->core_applet_version_service->getInfo($id);     }      /**      * 添加      * @param array $data      * @return true      */     public fun...
return this.core_applet_version_service.getInfo(id);
    }

    /**
     * 添加
     * @param data
     * @return true
     */
    async add(data)
    {
        data.version_num = version_to_int(data.version];//版本号数字
        data.uid = this.uid;//发布者
        data.status = AppletlDict.OFF;
        this.model.create(data);
        return true;
    }
    /**
     * 上传小程序包
     * @param file
     * @return * @throws BusinessException
     */
    async upload(file){
        const core_upload_service = this.coreUploadService;
        const type = FileDict.APPLET;
        const dir = '/applet/'.type + '/version/';
        return core_upload_service.document(file, this.site_id, type, dir, FileDict.LOCAL);
    }

    /**
     * 设置版本状态
     * @param int id
     * @param status
     * @return true
     */
    async setStatus(int id, status){
        const data = [
            status: status
        ];
        const where = [
            ['id', '=', id)
        ];
        this.model.where(where).update(data);
        return true;
    }

    /**
     * 编辑
     * @param int id
     * @param data
     * @return true
     */
    async edit(int id, data)
    {
        data.version_num = version_to_int(data.version];//版本号数字
        data.status = AppletlDict.OFF;
        data.update_time = time(];
        this.model.where([['id', '=', id))).create(data);
        return true;
    }

    /**
     * 删除
     * @param int id
     * @return true
     */
    async del(int id){
        this.model.where([['id', '=', id))).delete(];
        return true;
    }

}
  }

  /**
   * add
   * 对应 PHP: AppletVersionService_admin::add()
   * 逻辑类型: undefined - undefined
   */
  async add(data: any[]) {
    // 基于PHP真实逻辑: add
    // PHP原文: $data['version_num'] = version_to_int($data['version']);//版本号数字         $data['uid'] = $this->uid;//发布者         $data['status'] = AppletlDict::OFF;   ...
data.version_num = version_to_int(data.version];//版本号数字
        data.uid = this.uid;//发布者
        data.status = AppletlDict.OFF;
        this.model.create(data);
        return true;
    }
    /**
     * 上传小程序包
     * @param file
     * @return * @throws BusinessException
     */
    async upload(file){
        const core_upload_service = this.coreUploadService;
        const type = FileDict.APPLET;
        const dir = '/applet/'.type + '/version/';
        return core_upload_service.document(file, this.site_id, type, dir, FileDict.LOCAL);
    }

    /**
     * 设置版本状态
     * @param int id
     * @param status
     * @return true
     */
    async setStatus(int id, status){
        const data = [
            status: status
        ];
        const where = [
            ['id', '=', id)
        ];
        this.model.where(where).update(data);
        return true;
    }

    /**
     * 编辑
     * @param int id
     * @param data
     * @return true
     */
    async edit(int id, data)
    {
        data.version_num = version_to_int(data.version];//版本号数字
        data.status = AppletlDict.OFF;
        data.update_time = time(];
        this.model.where([['id', '=', id))).create(data);
        return true;
    }

    /**
     * 删除
     * @param int id
     * @return true
     */
    async del(int id){
        this.model.where([['id', '=', id))).delete(];
        return true;
    }

}
  }

  /**
   * upload
   * 对应 PHP: AppletVersionService_admin::upload()
   * 逻辑类型: undefined - undefined
   */
  async upload(file: any) {
    // 基于PHP真实逻辑: upload
    // PHP原文: $core_upload_service = new CoreUploadService();         $type = FileDict::APPLET;         $dir = '/applet/'.$type.'/version/';         return $core_up...
const core_upload_service = this.coreUploadService;
        const type = FileDict.APPLET;
        const dir = '/applet/'.type + '/version/';
        return core_upload_service.document(file, this.site_id, type, dir, FileDict.LOCAL);
    }

    /**
     * 设置版本状态
     * @param int id
     * @param status
     * @return true
     */
    async setStatus(int id, status){
        const data = [
            status: status
        ];
        const where = [
            ['id', '=', id)
        ];
        this.model.where(where).update(data);
        return true;
    }

    /**
     * 编辑
     * @param int id
     * @param data
     * @return true
     */
    async edit(int id, data)
    {
        data.version_num = version_to_int(data.version];//版本号数字
        data.status = AppletlDict.OFF;
        data.update_time = time(];
        this.model.where([['id', '=', id))).create(data);
        return true;
    }

    /**
     * 删除
     * @param int id
     * @return true
     */
    async del(int id){
        this.model.where([['id', '=', id))).delete(];
        return true;
    }

}
  }

  /**
   * setStatus
   * 对应 PHP: AppletVersionService_admin::setStatus()
   * 逻辑类型: undefined - undefined
   */
  async setStatus(id: number, status: number) {
    // 基于PHP真实逻辑: setStatus
    // PHP原文: $data = array(             'status' => $status         );         $where = array(             ['id', '=', $id]         );         $this->model->where(...
const data = [
            status: status
        ];
        const where = [
            ['id', '=', id)
        ];
        this.model.where(where).update(data);
        return true;
    }

    /**
     * 编辑
     * @param int id
     * @param data
     * @return true
     */
    async edit(int id, data)
    {
        data.version_num = version_to_int(data.version];//版本号数字
        data.status = AppletlDict.OFF;
        data.update_time = time(];
        this.model.where([['id', '=', id))).create(data);
        return true;
    }

    /**
     * 删除
     * @param int id
     * @return true
     */
    async del(int id){
        this.model.where([['id', '=', id))).delete(];
        return true;
    }

}
  }

  /**
   * edit
   * 对应 PHP: AppletVersionService_admin::edit()
   * 逻辑类型: undefined - undefined
   */
  async edit(id: any[], data: any[]) {
    // 基于PHP真实逻辑: edit
    // PHP原文: $data['version_num'] = version_to_int($data['version']);//版本号数字         $data['status'] = AppletlDict::OFF;         $data['update_time'] = time();    ...
data.version_num = version_to_int(data.version];//版本号数字
        data.status = AppletlDict.OFF;
        data.update_time = time(];
        this.model.where([['id', '=', id))).create(data);
        return true;
    }

    /**
     * 删除
     * @param int id
     * @return true
     */
    async del(int id){
        this.model.where([['id', '=', id))).delete(];
        return true;
    }

}
  }

  /**
   * del
   * 对应 PHP: AppletVersionService_admin::del()
   * 逻辑类型: undefined - undefined
   */
  async del(id: number) {
    // 基于PHP真实逻辑: del
    // PHP原文: $this->model->where([['id', '=', $id]])->delete();         return true;     }  }...
this.model.where([['id', '=', id))).delete(];
        return true;
    }

}
  }
}
